/*
package com.longcai.service.impl;

import com.longcai.entity.sys.SysRole;
import com.longcai.entity.sys.SysUser;
import com.longcai.repository.SysUserRepository;
import com.longcai.service.MyUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.user;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

*/
/**
 * @author Administrator
 * @Title: MyUserDetailsServiceImpl
 * @ProjectName spring-cloud-media
 * @Description: TODO
 * @date 2019/2/2111:58
 *//*

@Service("MyUserDetailsServiceImpl")
public class MyUserDetailsServiceImpl implements MyUserDetailsService, UserDetailsService {

    @Autowired
    private SysUserRepository sysUserRepository;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser sysUser = this.sysUserRepository.findByUsername(username);
        if (sysUser == null) {
            throw new UsernameNotFoundException("用户名不存在");
        }
        List<SimpleGrantedAuthority> authorities = new ArrayList<>();
        for (SysRole role : sysUser.getRoles()) {
            for (SysMenu permission : role.getPermissions()) {
                authorities.add(new SimpleGrantedAuthority(permission.getName()));
            }
        }
        return new user(sysUser.getUsername(), sysUser.getPassword(), authorities);
    }
}
*/
